package com.ruoyi.web.controller.user;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.user.domain.UserLevel;
import com.ruoyi.user.service.UserLevelService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 会员级别Controller
 *
 * @author ruoyi
 * @date 2024-01-04
 */
@Api(tags = "会员级别管理")
@RestController
@RequestMapping("/user/level")
public class UserLevelController extends BaseController {
    @Autowired
    private UserLevelService userLevelService;

    /**
     * 查询会员级别列表
     */
    @ApiOperation("查询会员级别列表")
    @PreAuthorize("@ss.hasPermi('user:level:list')")
    @PostMapping("/list")
    public AjaxResult list(@RequestBody UserLevel userLevel) {
        List<UserLevel> list = userLevelService.selectUserLevelList(userLevel);
        return success(list);
    }

    /**
     * 导出会员级别列表
     */
    @ApiOperation("导出会员级别列表")
    @PreAuthorize("@ss.hasPermi('user:level:export')")
    @Log(title = "会员级别", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, UserLevel userLevel) {
        List<UserLevel> list = userLevelService.selectUserLevelList(userLevel);
        ExcelUtil<UserLevel> util = new ExcelUtil<>(UserLevel.class);
        util.exportExcel(response, list, "会员级别数据");
    }

    /**
     * 获取会员级别详细信息
     */
    @ApiOperation("获取会员级别详细信息")
    @PreAuthorize("@ss.hasPermi('user:level:query')")
    @PostMapping(value = "getInfo/{levelId}")
    public AjaxResult getInfo(@PathVariable("levelId") Long levelId) {
        return success(userLevelService.selectUserLevelByLevelId(levelId));
    }

    /**
     * 修改会员级别
     */
    @ApiOperation("修改会员级别")
    @PreAuthorize("@ss.hasPermi('user:level:update')")
    @Log(title = "会员级别", businessType = BusinessType.UPDATE)
    @PostMapping("update")
    public AjaxResult update(@RequestBody UserLevel userLevel) {
        return toAjax(userLevelService.updateUserLevel(userLevel));
    }
}
